<?php //$Rev:: 33         $ // DO NOT REMOVE

class Connection
{

    public static function init($server, $port, $tries = 5, $sleep = 3, $timeout = 10)
    {
        // REQUIRES PHP 5.3.0
        $connect = function() use ($server, $port, $timeout) {
            if (false !== ($fp = @stream_socket_client('tcp://'.$server.':'.$port, $e1, $e2, $timeout))) {
                return $fp;
            }
            return false;
        };

        $i = 0;
        while ($i < $tries) {
            if (false !== ($conn = $connect())) {
                return $conn;
            }
            $tries++;
            sleep($sleep);
        }
        return false;
    }

}

?>